using System.Collections;
using UnityEngine;

public class EnemyState_LangGongShou_攻击 : EnemyStateBase_LangGongShou
{
	private Coroutine _Cor_攻击控制;

	private bool _Can三连 = true;

	public override void OnEnter()
	{
		_Mono._Ani.Play("攻击");
		_Timer = _Mono._Dict_Anis_name_time["攻击"];
		_Cor_攻击控制 = _Mono.StartCoroutine(Cor_攻击控制());
	}

	public override void OnExit()
	{
		if (_Cor_攻击控制 != null)
		{
			_Mono.StopCoroutine(_Cor_攻击控制);
			_Cor_攻击控制 = null;
		}
	}

	public override void OnUpdate()
	{
		_Timer -= Time.deltaTime;
		_Mono.transform.localScale = new Vector3((_Mono._Tsf_玩家.position.x > _Mono.transform.position.x) ? 1 : (-1), 1f, 1f);
		if (_Timer <= 0f)
		{
			_Mono.ChangeState(StateType_Enemy_LangGongShou.追击);
		}
	}

	private void F_三连CD()
	{
		_Can三连 = true;
	}

	private IEnumerator Cor_攻击控制()
	{
		_Mono._Rb2D.velocity = Vector2.zero;
		float time3;
		if (_Can三连 && Random.value < 0.5f)
		{
			time3 = 0f;
			_Can三连 = false;
			_Mono.Invoke("F_三连CD", 6f);
			while (time3 < 0.6f)
			{
				if (!_Mono._Is被定)
				{
					time3 += Time.deltaTime;
				}
				yield return null;
			}
			F_发射弓箭();
			time3 = 0f;
			while (time3 < 0.12f)
			{
				if (!_Mono._Is被定)
				{
					time3 += Time.deltaTime;
				}
				yield return null;
			}
			F_发射弓箭();
			time3 = 0f;
			while (time3 < 0.12f)
			{
				if (!_Mono._Is被定)
				{
					time3 += Time.deltaTime;
				}
				yield return null;
			}
			F_发射弓箭();
			yield break;
		}
		time3 = 0f;
		while (time3 < 0.7f)
		{
			if (!_Mono._Is被定)
			{
				time3 += Time.deltaTime;
			}
			yield return null;
		}
		F_发射弓箭();
	}

	private void F_发射弓箭()
	{
		MonoSingleton<AudioManager>.Instance.F_Play_SFX(_Mono._AudioC_弓狼射箭);
		Object.Instantiate(_Mono._弓箭Prefab, _Mono.transform.position, Quaternion.identity).F_Init((_Mono._Tsf_玩家.position - _Mono.transform.position).normalized, _Mono._Data._Atk);
	}
}
